package triangulation;

import java.util.ArrayList;
import java.util.HashSet;
import sample.Edge;
import sample.Vertex;


public class Triangle extends Polygon{
	private ArrayList<Edge> edgeList;
	public int label;
	
	public Triangle(Edge e1, Edge e2, Edge e3){
		edgeList = new ArrayList<Edge>();
		edgeList.add(e1);
		edgeList.add(e2);
		edgeList.add(e3);
	}
	
	public ArrayList<Edge> getEdges()
	{
		return edgeList;
	}
	
	public ArrayList<Vertex> getVertices()
	{
		ArrayList<Vertex> vertices = new ArrayList<Vertex>();
		HashSet<Vertex> hashVertex = new HashSet<Vertex>();
		
		for(Edge e : edgeList){
			hashVertex.add(e.getSource());
			hashVertex.add(e.getTarget());
		}
		
		vertices.addAll(hashVertex);
		
//		for (Vertex v : vertices)
//		{
//			System.out.println(v);
//		}
		
		return vertices;
	}
	
	
	public String toString(){
		String s = "L:"+label+": (";
		
		for(Edge e : edgeList){
			s = s + e.getSource()+","+e.getTarget()+"),(";
		}
		
		return s;
	}
	
	@Override
	public int hashCode()
	{
		final int prime = 31;
		int result = 1;
		result = prime * result + ((edgeList == null) ? 0 : edgeList.hashCode());
		return result;
	}

	public boolean equals(Object o)
	{
		Triangle t = (Triangle)o;
		
		HashSet<Edge> hashEdge = new HashSet<Edge>();
		
		for(Edge e : t.edgeList){
			hashEdge.add(e);
		}
		
		for(Edge e : edgeList){
			hashEdge.add(e);
		}
		
		if(hashEdge.size() > 3)
			return false;
		else
			return true;
	}
}
